package org.jeecg.modules.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.util.SsoUtil;
import org.jeecg.modules.system.entity.SysRole;
import org.jeecg.modules.system.mapper.SysRoleMapper;
import org.jeecg.modules.system.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @Author scott
 * @since 2018-12-19
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

   @Autowired
   private SysRoleMapper sysRoleMapper;
    @Override
    public Integer selectRoleExist(Map map) {
        return sysRoleMapper.selectRoleExist(map);
    }
    @Override
    public IPage<SysRole> findServerPage(Page<SysRole> page, SysRole role) {
        return sysRoleMapper.findServerPage(page,role);
    }

    @Override
    public List<SysRole> queryServerRoleTreeList(String tenantId) {
        return sysRoleMapper.queryServerRoleTreeList(tenantId);
    }

    @Override
    public void serverSave(SysRole role) {
        role.setId(String.valueOf(IdWorker.getId()));
        role.setCreateBy(SsoUtil.getLoginUser().getId());
        role.setCreateTime(new Date());
        role.setUpdateBy(SsoUtil.getLoginUser().getId());
        role.setUpdateTime(new Date());
        role.setDelFlag(CommonConstant.DEL_FLAG_0.toString());
        sysRoleMapper.serverSave(role);
    }

}
